home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 6 / The Arsenal Files 6 (Arsenal Computer).ISO / prg_basi / ddfedit.zip / DDFFILE.FRM < prev    next >
Text File  |  1996-02-05  |  14KB  |  476 lines

  1. VERSION 2.00
  2. Begin Form FormFileDDF 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "List of Files"
  5.    ClientHeight    =   3825
  6.    ClientLeft      =   2670
  7.    ClientTop       =   3630
  8.    ClientWidth     =   5925
  9.    Height          =   4230
  10.    Left            =   2610
  11.    LinkTopic       =   "Form1"
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   3825
  14.    ScaleWidth      =   5925
  15.    Top             =   3285
  16.    Width           =   6045
  17.    Begin SSPanel PanTop 
  18.       Align           =   1  'Align Top
  19.       AutoSize        =   3  'AutoSize Child To Panel
  20.       BevelOuter      =   0  'None
  21.       BorderWidth     =   1
  22.       Height          =   495
  23.       Left            =   0
  24.       TabIndex        =   3
  25.       Top             =   0
  26.       Width           =   5925
  27.       Begin CommandButton FldCom 
  28.          Caption         =   "Cre&ate"
  29.          Height          =   255
  30.          Index           =   6
  31.          Left            =   2880
  32.          TabIndex        =   12
  33.          Top             =   0
  34.          Width           =   735
  35.       End
  36.       Begin CommandButton FldCom 
  37.          Caption         =   "&Index"
  38.          Height          =   255
  39.          Index           =   5
  40.          Left            =   2160
  41.          TabIndex        =   11
  42.          Top             =   0
  43.          Width           =   735
  44.       End
  45.       Begin CommandButton FldCom 
  46.          Caption         =   "&Close"
  47.          Height          =   255
  48.          Index           =   4
  49.          Left            =   4545
  50.          TabIndex        =   10
  51.          Top             =   0
  52.          Width           =   735
  53.       End
  54.       Begin CommandButton FldCom 
  55.          Caption         =   "&Fields"
  56.          Height          =   255
  57.          Index           =   2
  58.          Left            =   1440
  59.          TabIndex        =   9
  60.          Top             =   0
  61.          Width           =   735
  62.       End
  63.       Begin CommandButton FldCom 
  64.          Caption         =   "&New"
  65.          Height          =   255
  66.          Index           =   0
  67.          Left            =   0
  68.          TabIndex        =   6
  69.          Top             =   0
  70.          Width           =   735
  71.       End
  72.       Begin CommandButton FldCom 
  73.          Caption         =   "&Edit"
  74.          Height          =   255
  75.          Index           =   1
  76.          Left            =   720
  77.          TabIndex        =   5
  78.          Top             =   0
  79.          Width           =   735
  80.       End
  81.       Begin CommandButton FldCom 
  82.          Caption         =   "&Delete"
  83.          Height          =   255
  84.          Index           =   3
  85.          Left            =   3825
  86.          TabIndex        =   4
  87.          Top             =   0
  88.          Width           =   735
  89.       End
  90.       Begin SSPanel PanHead 
  91.          AutoSize        =   3  'AutoSize Child To Panel
  92.          BevelInner      =   1  'Inset
  93.          BevelOuter      =   0  'None
  94.          BorderWidth     =   1
  95.          Height          =   255
  96.          Left            =   0
  97.          TabIndex        =   7
  98.          Top             =   240
  99.          Width           =   5475
  100.          Begin TextBox TextTop 
  101.             BackColor       =   &H00C0C0C0&
  102.             BorderStyle     =   0  'None
  103.             Enabled         =   0   'False
  104.             ForeColor       =   &H00FF0000&
  105.             Height          =   195
  106.             Left            =   30
  107.             MultiLine       =   -1  'True
  108.             TabIndex        =   8
  109.             Text            =   "test test test"
  110.             Top             =   30
  111.             Width           =   5415
  112.          End
  113.       End
  114.    End
  115.    Begin TextBox XPath 
  116.       Height          =   285
  117.       Left            =   120
  118.       TabIndex        =   2
  119.       Top             =   1200
  120.       Visible         =   0   'False
  121.       Width           =   180
  122.    End
  123.    Begin SSPanel PanList 
  124.       AutoSize        =   3  'AutoSize Child To Panel
  125.       BevelInner      =   1  'Inset
  126.       BevelOuter      =   0  'None
  127.       BorderWidth     =   1
  128.       Height          =   870
  129.       Left            =   0
  130.       TabIndex        =   0
  131.       Top             =   240
  132.       Width           =   3000
  133.       Begin ListBox Llist 
  134.          Height          =   810
  135.          Left            =   30
  136.          TabIndex        =   1
  137.          Top             =   30
  138.          Width           =   2940
  139.       End
  140.    End
  141. End
  142. Option Explicit
  143. Dim inited As Integer
  144.  
  145. Sub Field_edit ()
  146.   Dim Keybuf As KeyBufDef
  147.   Dim KeyBufLen As Integer
  148.   Dim XDFile As XDFile_def
  149.   Dim BufLen As Integer
  150.   Dim stat As Integer
  151.   Dim PosBlk As PosBlkDef
  152.   Dim FileFullPath As String
  153.   Dim XDFileKey1 As XDFileKey0_def
  154.   Dim FieldForm As New FormFieldDDF
  155.   Dim i As Integer
  156.  
  157.   If llist.ListIndex = -1 Then Exit Sub
  158.   ' look to see if a field form exists already for this file
  159.  
  160.   For i = 0 To Forms.Count - 1
  161.     If Forms(i).Tag = "D" & Format(llist.ItemData(llist.ListIndex), "0") Then
  162.       Forms(i).SetFocus
  163.       If Forms(i).WindowState = 1 Then Forms(i).WindowState = 0
  164.       Exit Sub
  165.     End If
  166.   Next i
  167.   
  168.   
  169.   FileFullPath = XPath.Text & "FILE.DDF"
  170.   
  171.   Keybuf.kb = FileFullPath
  172.   KeyBufLen = Len(Keybuf)
  173.   BufLen = 0
  174.   
  175.  
  176.   stat = btrcall(B_OPEN, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  177.   If stat <> 0 Then
  178.     MsgBox "Btrieve Error Opening file " & FileFullPath & Chr(10) & stat & " " & BtErr(stat)
  179.     Exit Sub
  180.   End If
  181.  
  182.  
  183.   XDFileKey1.XFDid = llist.ItemData(llist.ListIndex)
  184.   KeyBufLen = Len(XDFileKey1): BufLen = Len(XDFile)
  185.   stat = btrcall(B_GETEQ, PosBlk, XDFile, BufLen, XDFileKey1, KeyBufLen, 0)
  186.  
  187.   If stat <> 0 Then
  188.     MsgBox "Btrieve Error Retrieving Record in FILE.DDF " & Chr(10) & stat & " " & BtErr(stat)
  189.   Else
  190.     Load FieldForm
  191.     FieldForm.XPath.Text = XPath.Text
  192.     FieldForm.Tag = "D" & Format(XDFile.XFDid, "0")
  193.     FieldForm.XFDid.Text = Format(XDFile.XFDid, "0")
  194.     FieldForm.XFDName.Text = XDFile.XFDName
  195.     FieldForm.XFDLocation.Text = XDFile.XFDLocation
  196.     FieldForm.XFDFlags.Text = Format(Asc(XDFile.XFDFlags), "0")
  197.     
  198.   End If
  199.   
  200.   stat = btrcall(B_CLOSE, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  201.  
  202. End Sub
  203.  
  204. Sub File_Create ()
  205.   Dim FileID As Integer
  206.   Dim Location As String
  207.   Dim p1 As Integer, p2 As Integer
  208.   Dim ll As String
  209.   
  210.  
  211.   If llist.ListIndex = -1 Then Exit Sub
  212.  
  213.   FileID = llist.ItemData(llist.ListIndex)
  214.  
  215.   If FileID < 4 Then
  216.     MsgBox "You CANNOT recreate Dictionary Files !", , "Hmmmm.."
  217.     Exit Sub
  218.   End If
  219.  
  220.   If MsgBox("Recreating File will completely Erase all data in previous version" & Chr(10) & "Are you Sure you wish to proceed ?", 4 + 16, "WARNING") <> 6 Then Exit Sub
  221.  
  222.   ' extract the file's location from the list box !
  223.   ll = llist.List(llist.ListIndex)
  224.  
  225.   ' skip the first tab
  226.   p1 = 1: p2 = InStr(p1, ll, Chr(9))
  227.  
  228.   p1 = p2 + 1: p2 = InStr(p1, ll, Chr(9))
  229.   Location = Trim(Mid(ll, p1, p2 - p1))
  230.  
  231.   Create_btrfile (XPath.Text), Location, FileID
  232.  
  233. End Sub
  234.  
  235. Sub File_Delete ()
  236.   Dim idx As Integer, xfid As Integer
  237.   idx = llist.ListIndex
  238.   If idx < 0 Then Exit Sub
  239.   If idx < 3 Then
  240.     MsgBox "You CANNOT delete the system Files !", , "ERROR"
  241.     Exit Sub
  242.   End If
  243.  
  244.  
  245.   If MsgBox("Are you SURE you wish to Delete Selected file" & Chr(10) & "And all relevant Fields ?", 16 + 4, "Delete File") = 6 Then
  246.     File_Remove (XPath.Text), (llist.ItemData(llist.ListIndex))
  247.     listfill
  248.   End If
  249.  
  250.  
  251. End Sub
  252.  
  253. Sub File_edit ()
  254.   Dim p1 As Integer, p2 As Integer
  255.   Dim ll As String
  256.   Dim idx As Integer
  257.   idx = llist.ListIndex
  258.   
  259.   If idx = -1 Then Exit Sub
  260.   If idx < 3 Then
  261.     MsgBox "You CANNOT edit the system Files !", , "ERROR"
  262.     Exit Sub
  263.   End If
  264.   
  265.   ll = llist.List(idx)
  266.   Load FormNewFile
  267.   p1 = 1: p2 = InStr(p1, ll, Chr(9))
  268.   FormNewFile.NewFileName.Text = Trim(Mid(ll, p1, p2 - p1))
  269.   
  270.   p1 = p2 + 1: p2 = InStr(p1, ll, Chr(9))
  271.   FormNewFile.NewFileLocation.Text = Trim(Mid(ll, p1, p2 - p1))
  272.   
  273.   FormNewFile.Caption = "Edit File"
  274.   FormNewFile.XPath.Text = XPath.Text
  275.   FormNewFile.NewFileIDX.Text = Format(llist.ItemData(idx), "0")
  276.   FormNewFile.Show 1
  277.   listfill
  278.  
  279. End Sub
  280.  
  281. Sub File_New ()
  282.   Dim last As Integer
  283.   Load FormNewFile
  284.   FormNewFile.Caption = "Add New File"
  285.   FormNewFile.XPath.Text = XPath.Text
  286.   FormNewFile.NewFileIDX.Text = "-1"
  287.   FormNewFile.Show 1
  288.   last = llist.ListCount
  289.   listfill
  290.   If llist.ListCount <> last Then
  291.     llist.ListIndex = llist.ListCount - 1
  292.     Field_edit
  293.   End If
  294. End Sub
  295.  
  296. Sub FldCom_Click (index As Integer)
  297.   Select Case index
  298.     Case 0: File_New ' new
  299.     Case 1: File_edit ' edit
  300.     Case 2: Field_edit
  301.     Case 3: File_Delete ' delete
  302.     Case 4: Unload Me
  303.     Case 5: Index_edit
  304.     Case 6: File_Create
  305.   End Select
  306.  
  307. End Sub
  308.  
  309. Sub Form_Activate ()
  310.   If inited Then Exit Sub
  311.   Me.Caption = "Files in " & XPath
  312.   listfill
  313. End Sub
  314.  
  315. Sub Form_Load ()
  316.   inited = False
  317. End Sub
  318.  
  319. Sub Form_Resize ()
  320.   If WindowState = 1 Then Exit Sub
  321.   PanHead.Left = 0
  322.   PanHead.Width = PanTop.Width
  323.   PanList.Left = 0
  324.   PanList.Width = ScaleWidth
  325.   PanList.Top = PanTop.Height
  326.   PanList.Height = ScaleHeight - PanList.Top
  327. End Sub
  328.  
  329. Sub Form_Unload (Cancel As Integer)
  330.   Dim Found As Integer, i As Integer
  331.   Dim MyPath As String
  332.   MyPath = Trim(XPath.Text)
  333.   Debug.Print "****  CLOSING CHILD FORMS "; MyPath
  334.   Do
  335.     Found = False
  336.     For i = 1 To Forms.Count - 1 ' skip main form !
  337.       Debug.Print Trim(Forms(i).XPath.Text), Trim(MyPath)
  338.       If Trim(Forms(i).XPath.Text) = Trim(MyPath) Then
  339.         If Forms(i).Caption <> Me.Caption Then
  340.           Debug.Print "FOUND " & Forms(i).Caption
  341.           Found = True
  342.           Unload Forms(i)
  343.           Exit For
  344.         End If
  345.       End If
  346.     Next i
  347.     If Found = False Then Exit Do
  348.   Loop
  349.  
  350. End Sub
  351.  
  352. Sub Index_edit ()
  353.   Dim Keybuf As KeyBufDef
  354.   Dim KeyBufLen As Integer
  355.   Dim XDFile As XDFile_def
  356.   Dim BufLen As Integer
  357.   Dim stat As Integer
  358.   Dim PosBlk As PosBlkDef
  359.   Dim FileFullPath As String
  360.   Dim XDFileKey1 As XDFileKey0_def
  361.   Dim IndexForm As New FormIndexDDF
  362.   Dim i As Integer
  363.  
  364.   If llist.ListIndex = -1 Then Exit Sub
  365.   ' look to see if a field form exists already for this file
  366.  
  367.   For i = 0 To Forms.Count - 1
  368.     If Forms(i).Tag = "D" & Format(llist.ItemData(llist.ListIndex), "0") Then
  369.       Forms(i).SetFocus
  370.       If Forms(i).WindowState = 1 Then Forms(i).WindowState = 0
  371.       Exit Sub
  372.     End If
  373.   Next i
  374.   
  375.   
  376.   FileFullPath = XPath.Text & "FILE.DDF"
  377.   
  378.   Keybuf.kb = FileFullPath
  379.   KeyBufLen = Len(Keybuf)
  380.   BufLen = 0
  381.   
  382.  
  383.   stat = btrcall(B_OPEN, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  384.   If stat <> 0 Then
  385.     MsgBox "Btrieve Error Opening file " & FileFullPath & Chr(10) & stat & " " & BtErr(stat)
  386.     Exit Sub
  387.   End If
  388.  
  389.  
  390.   XDFileKey1.XFDid = llist.ItemData(llist.ListIndex)
  391.   KeyBufLen = Len(XDFileKey1): BufLen = Len(XDFile)
  392.   stat = btrcall(B_GETEQ, PosBlk, XDFile, BufLen, XDFileKey1, KeyBufLen, 0)
  393.  
  394.   If stat <> 0 Then
  395.     MsgBox "Btrieve Error Retrieving Record in FILE.DDF " & Chr(10) & stat & " " & BtErr(stat)
  396.   Else
  397.     Load IndexForm
  398.     IndexForm.XPath.Text = XPath.Text
  399.     IndexForm.Tag = "D" & Format(XDFile.XFDid, "0")
  400.     IndexForm.XFDid.Text = Format(XDFile.XFDid, "0")
  401.     IndexForm.XFDName.Text = XDFile.XFDName
  402.     IndexForm.XFDLocation.Text = XDFile.XFDLocation
  403.     IndexForm.XFDFlags.Text = Format(Asc(XDFile.XFDFlags), "0")
  404.     
  405.   End If
  406.   
  407.   stat = btrcall(B_CLOSE, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  408.  
  409. End Sub
  410.  
  411. Sub listfill ()
  412.  
  413.   Dim Keybuf As KeyBufDef
  414.   Dim KeyBufLen As Integer
  415.   Dim XDFile As XDFile_def
  416.   Dim BufLen As Integer
  417.   Dim stat As Integer
  418.   Dim PosBlk As PosBlkDef
  419.   Dim FileFullPath As String
  420.   Dim X As Integer
  421.   Dim WhosFile As String
  422.  
  423.   llist.Clear
  424.  
  425.   KeyBufLen = Len(Keybuf)
  426.   BufLen = Len(XDFile)
  427.  
  428.   ' first open the file
  429.   FileFullPath = XPath.Text & "FILE.DDF"
  430.   Keybuf.kb = FileFullPath
  431.   KeyBufLen = Len(Keybuf)
  432.   BufLen = 0
  433.   
  434.   stat = btrcall(B_OPEN, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  435.   If stat <> 0 Then
  436.     MsgBox "Btrieve Error Opening file " & FileFullPath & Chr(10) & stat & " " & BtErr(stat)
  437.     Exit Sub
  438.   End If
  439.  
  440.  
  441.   KeyBufLen = Len(Keybuf): BufLen = Len(XDFile)
  442.   stat = btrcall(B_GETLW, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  443.   
  444. '  Texttop.Text = "Id" & Chr(9) & "Name" & Chr(9) & "Location" & Chr(9) & "Owner" & Chr(9) & "Reserved"
  445.   Texttop.Text = "Name" & Chr(9) & "Location" & Chr(9) & "Owner" & Chr(9) & "Reserved"
  446.   Do
  447.     If stat <> 0 Then Exit Do
  448.  
  449.     If Asc(XDFile.XFDFlags) = 16 Then
  450.       WhosFile = "*SYS"
  451.     Else
  452.       WhosFile = "User"
  453.     End If
  454.     'llist.AddItem XDFile.XFDid & Chr(9) & Trim(XDFile.XFDName) & Chr(9) & Trim(XDFile.XFDLocation) & Chr(9) & WhosFile & Chr(9) & Trim(XDFile.XFDReserved)
  455.     llist.AddItem Trim(XDFile.XFDName) & Chr(9) & Trim(XDFile.XFDLocation) & Chr(9) & WhosFile & Chr(9) & Trim(XDFile.XFDReserved)
  456.     llist.ItemData(llist.NewIndex) = XDFile.XFDid
  457.  
  458.     KeyBufLen = Len(Keybuf): BufLen = Len(XDFile)
  459.     stat = btrcall(B_GETNX, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  460.   Loop
  461.  
  462.   If stat <> 9 Then MsgBox "Btrieve Error Retrieving Record in FILE file " & Chr(10) & stat & " " & BtErr(stat)
  463.   
  464.   
  465.   stat = btrcall(B_CLOSE, PosBlk, XDFile, BufLen, Keybuf, KeyBufLen, 0)
  466.   
  467.   X = AutoSetTabStopsCheck(llist, Texttop, False, False)
  468.   inited = True
  469. End Sub
  470.  
  471. Sub Llist_DblClick ()
  472.   Field_edit
  473.  
  474. End Sub
  475.  
  476.